package com.example.administrator.pomelostreet.mine;

import android.app.Activity;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

import com.example.administrator.pomelostreet.R;
import com.umeng.socialize.Config;
import com.umeng.socialize.PlatformConfig;
import com.umeng.socialize.UMAuthListener;
import com.umeng.socialize.UMShareAPI;
import com.umeng.socialize.bean.SHARE_MEDIA;
import com.umeng.socialize.utils.Log;

import java.util.Map;
import java.util.Set;

public class DengLu extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_deng_lu);
        PlatformConfig.setSinaWeibo("1952865082", "f05505daaba575a40f8c2fa42fea09f4");
        Config.DEBUG=true;
        final UMShareAPI shareAPI = UMShareAPI.get(this);
        findViewById(R.id.roundedImageView_weibo).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                denglu(shareAPI);

            }
        });
        findViewById(R.id.roundedImageView_qq).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
            denglu(shareAPI);
            }
        });
        findViewById(R.id.roundedImageView_weixin).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                denglu(shareAPI);
            }
        });
        findViewById(R.id.denglu).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                EditText etAdmin= (EditText) findViewById(R.id.et_admin);
                Editable admin = etAdmin.getText();
                EditText etPassword= (EditText) findViewById(R.id.et_password);
                Editable password = etPassword.getText();
                if (!TextUtils.isEmpty(admin)&&!TextUtils.isEmpty(password)){
                    finish();
                }else {
                    Toast.makeText(DengLu.this,"账号或密码不能为空",Toast.LENGTH_SHORT).show();
                }
            }
        });
    }

    private void denglu(UMShareAPI shareAPI) {
        shareAPI.getPlatformInfo(DengLu.this
                , SHARE_MEDIA.SINA
                , new UMAuthListener() {
                    @Override
                    public void onComplete(SHARE_MEDIA share_media, int i, Map<String, String> map) {
                        Set<Map.Entry<String, String>> entries = map.entrySet();
                        for (Map.Entry<String, String> entry : entries) {
                            Log.i("========", "key:" + entry.getKey() + ",value:" + entry.getValue());
                        }
                    }

                    @Override
                    public void onError(SHARE_MEDIA share_media, int i, Throwable throwable) {

                    }

                    @Override
                    public void onCancel(SHARE_MEDIA share_media, int i) {

                    }
                });
    }
}
